package com.lingkang.flychat.service.impl;

import com.lingkang.flychat.domain.FcMessage;
import com.lingkang.flychat.domain.FcUser;
import com.lingkang.flychat.dto.ResponseResult;
import com.lingkang.flychat.dto.WsMessage;
import com.lingkang.flychat.mapper.FcFriendMapper;
import com.lingkang.flychat.mapper.FcMessageMapper;
import com.lingkang.flychat.mapper.FcUserMapper;
import com.lingkang.flychat.service.RedisService;
import com.lingkang.flychat.service.UserService;
import com.lingkang.flychat.vo.FriendListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author linke
 * @date 2020/4/6 16:04
 * @description
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private RedisService redisService;
    @Autowired
    private FcUserMapper fcUserMapper;
    @Autowired
    private FcFriendMapper fcFriendMapper;
    @Autowired
    private FcMessageMapper fcMessageMapper;

    @Override
    public ResponseResult info(String username) {
        FcUser fcUser = fcUserMapper.getInfo(username);
        return new ResponseResult(0, fcUser);
    }

    @Override
    public ResponseResult friendList(String username) {
        List<FriendListVo> listVo = fcFriendMapper.getList(username);
        return new ResponseResult(0, listVo);
    }

    @Override
    public void sendMessageToFriend(WsMessage message, int isRead) {
        FcMessage fcMessage = new FcMessage();
        fcMessage.setIsRead(isRead);
        fcMessage.setContent(message.getContent());
        fcMessage.setSendTime(new Date());
        fcMessage.setSendUsername(message.getSendUser());
        fcMessage.setReceiveUsername(message.getReceiveUser());
        fcMessageMapper.insertSelective(fcMessage);
    }
}
